<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>我的</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css"/>
    <style>
        body {
            font-size: 14px;
            background: #f3f3ff;
        }

        header.headerBuyer {
            background: url(../image/seller.jpg) !important;
        }

        header {
            background: url(../image/buyer.jpg);
            position: relative;
            color: #fff;
            font-weight: 400;
        }

        header .aui-input-row:first-child:after {
            border: none;
        }

        header .aui-border-r:after {
            bottom: -60%;
            top: 18%;
        }

        header .imgRadius {
            border-radius: 50%;
            width: 80px;
            overflow: hidden;
            height: 80px;
            margin-right: 15px;
            float: left;
        }

        header .imgRadius img {
            width: 100%;
        }

        .divTable {
            display: block;
            /*box-sizing: content-box;*/
            padding: 20px;
            height: 120px;
        }

        /*.divCell {*/
        /*display: table-cell;*/
        /*vertical-align: middle;*/
        /*}*/

        .my-menu {
            width: 100%;
            height: 45px;
            line-height: 45px;
            left: 0;
            bottom: 0;
            text-align: center;
            background: #ffffff;
            filter: Alpha(opacity=50);
            background: rgba(0, 0, 0, 0.2) none repeat scroll 0 0 !important;
            color: #ffffff;
            font-size: 14px;
        }

        .myMessage {
            position: relative;
        }

        .myMessage:before {
            content: "";
            position: absolute;
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: red;
            right: -6px;
            top: -6px;
        }

        .aui-grid-sixteen li p {
            font-size: 12px;
            margin-top: -5px;
        }

        .aui-grid-sixteen li span {
            color: #9c9c9c;
            font-size: 20px;
            line-height: 44px;
        }

        .aui-list-view {
            margin-bottom: 0;
        }

        .aui-badge {
            background: none;
        }

        .my-nav {
            padding-bottom: 10px;
            margin-bottom: 10px;
        }

        .my-nav p {
            font-size: 12px;
        }

        .my-nav.aui-grid-sixteen li:after {
            border: none
        }

        .my-nav li {
            padding: 0;
        }

        .aui-list-view-cell:last-child:after {
            border: none;
        }

        .aui-grid-sixteen:after {
            /*border:none;*/
        }

        .w20 {
            width: 20%;
        }

        .aui-badge {
            color: #9c9c9c;
        }

        .aui-list-view i.aui-iconfont {
            border-radius: 50%;
        }

        .aui-list-view .qianbao {
            background: #f67b86 !important;
        }

        .aui-list-view .gong {
            background: #f97406 !important;
        }

        .aui-list-view .fabu {
            background: #8ca6c6 !important;
        }

        .aui-list-view .fuwu {
            background: #f79136 !important;
        }

        .aui-list-view .buhuo {
            background: #8ca8c7 !important;
        }

        .aui-list-view .shoucang {
            background: #f5ad1b !important;
        }

        .aui-list-view .zuji {
            background: #5ac3a9 !important;
        }

        .aui-list-view .yijian {
            background: #83a9ce !important;
        }

        .my-list {
            margin-bottom: 10px;
        }

        .aui-list-view:after {
            top: 100%;
        }

        .seller {
            display: none;
        }

        .aui-list-view-cell:after {
        }

        .companyName {
            display: block;
            height: 80px;
            line-height: 80px;
        }

        .divCell .aui-btn-info {
            padding: 2px 4px !important;
            float: left;
            margin-left: 5px;
            display: none;
        }

    </style>
</head>
<body>
<header>
    <div class="aui-input-row divTable" tapmode onclick="go2User(user_id)">
        <div id="individualFrame">
            <div class="imgRadius headerPic">
                <img src="../image/touxiang.jpg">
            </div>
            <div class="companyName">---</div>
        </div>

        <div id="companyFrame" style="display: none;">
            <div class="imgRadius headerPic">
                <img src="../image/touxiang.jpg">
            </div>
            <div class="companyName">---</div>
        </div>
    </div>
    <div class="my-menu">
        <div class="aui-col-xs-4 aui-border-r buyer" id="switch2Seller" tapmode>切换为卖家</div>
        <div class="aui-col-xs-4 aui-border-r seller" id="switch2Buyer" tapmode>切换为买家</div>
        <div class="aui-col-xs-4 aui-border-r " tapmode onclick="go2News();">
            <span class="noMessage">我的消息</span>
        </div>
        <div class="aui-col-xs-4" tapmode onclick="openToTwo('my/setting')">设置</div>
    </div>
</header><!-- /header -->
<!-- 默认是买家，切换卖家时，如果还没认证就提示认证，如果认证了，就直接切换 -->
<div class="contains">
    <div class="aui-content">

        <ul class="aui-list-view">
            <li class="aui-list-view-cell seller" tapmode onclick="openToTwo('my/sellerOrderList_win')">
                <a class="aui-arrow-right">
                    已卖出的货品
                    <span class="aui-badge">全部订单</span>
                </a>
            </li>
            <li class="aui-list-view-cell buyer" tapmode onclick="openToTwo('my/buyerOrderList_win')">
                <a class="aui-arrow-right">
                    已买到的货品
                    <span class="aui-badge">全部订单</span>
                </a>
            </li>
        </ul>

        <ul class="aui-grid-sixteen my-nav">
            <li class="w20 aui-text-center" tapmode onclick="goToOrderList(1)">
                <!-- <span class="aui-iconfont  " id="pendingPayment">0</span> -->
                <span id="pendingPayment">--</span>

                <p>待付款</p>
            </li>
            <li class="w20 aui-text-center" tapmode onclick="goToOrderList(2)">
                <!-- <span class="aui-iconfont  " id="alreadyPaid">0</span> -->
                <span id="alreadyPaid">--</span>

                <p>待发货</p>
            </li>
            <li class="w20 aui-text-center" tapmode onclick="goToOrderList(3)">
                <!-- <span class="aui-iconfont  " id="alreadyShipped">0</span> -->
                <span id="alreadyShipped">--</span>

                <p>待确认收货</p>
            </li>
            <li class="w20 aui-text-center" tapmode onclick="goToOrderList(4)">
                <!-- <span class="aui-iconfont  " id="SuccessfulTrade">0</span> -->
                <span id="SuccessfulTrade">--</span>

                <p>待评价</p>
            </li>
            <li class="w20 aui-text-center">
                <!-- <span class="aui-iconfont  " id="returns">0</span> -->
                <span id="returns">--</span>

                <p>退款中</p>
            </li>
        </ul>
        <!-- 卖家 -->
        <div class="seller">
            <ul class="aui-list-view my-list ">
                <li class="aui-list-view-cell" tapmode onclick="openToTwo('my/wallet_win')">
                    <a class="aui-arrow-right">
                        <i class="aui-iconfont aui-icon-recharge aui-bg-info qianbao"></i>钱包
                        <span class="aui-badge">当前金额：<span id="userMoney">0.00</span></span>
                    </a>
                </li>
            </ul>
            <!-- 卖家 -->
            <ul class="aui-list-view my-list ">
                <li class="aui-list-view-cell" tapmode onclick="openToTwo('my/proManage_win')">
                    <a class="aui-arrow-right">
                        <i class="aui-iconfont  aui-bg-info gong">供</i>供应管理
                        <span class="aui-badge">便捷管理供应商品</span>
                    </a>
                </li>
                <li class="aui-list-view-cell" tapmode onclick="openToTwo('my/release_win')">
                    <a class="aui-arrow-right">
                        <i class="aui-iconfont aui-icon-camera aui-bg-info fabu"></i>快速发布
                        <span class="aui-badge">发布商品如此简单</span>
                    </a>
                </li>
            </ul>
        </div>

        <!-- 买家 -->
        <div class="buyer">
            <ul class="aui-list-view my-list ">
                <!--<li class="aui-list-view-cell" tapmode onclick="openToTwo('my/replenish_win')">-->
                <!--<a class="aui-arrow-right">-->
                <!--<i class="aui-iconfont  aui-icon-light aui-bg-info buhuo"></i>快速补货-->
                <!--<span class="aui-badge">一键补货轻松搞定</span>-->
                <!--</a>-->
                <!--</li>-->
                <li class="aui-list-view-cell" tapmode onclick="openToTwo('my/favorite_win')">
                    <a class="aui-arrow-right">
                        <i class="aui-iconfont aui-icon-favor aui-bg-info shoucang"></i>收藏夹
                        <span class="aui-badge">我收藏的好商好品</span>
                    </a>
                </li>
                <li class="aui-list-view-cell" tapmode onclick="openToTwo('my/addressList_win')">
                    <a class="aui-arrow-right">
                        <i class="aui-iconfont aui-icon-footprint aui-bg-info zuji"></i>收货地址
                        <span class="aui-badge">我的收货地址</span>
                    </a>
                </li>
            </ul>
            <ul class="aui-list-view my-list ">
                <li class="aui-list-view-cell" tapmode onclick="openToTwo('my/sendProblem_win')">
                    <a class="aui-arrow-right">
                        <i class="aui-iconfont aui-icon-calendar aui-bg-info yijian"></i>意见反馈
                        <span class="aui-badge"></span>
                    </a>
                </li>
            </ul>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/myInfo.js"></script>
<script type="text/javascript" src="../script/jquery-1.11.3.js"></script>
<script type="text/javascript">
    var imgBase64;
    var identitySwitch = "buyer"//用户类型
    var myInfoData;
    apiready = function () {
        api.parseTapmode();
        //getInfo();
        identitySwitch = 'buyer';
        getStorageAll();
        if (nick_name == "") {
            $('.companyName').text("单击设置昵称");
        } else {
            $('.companyName').text(nick_name);
        }
        if (head_pic == "") {
            $(".headerPic").find("img").eq(0).attr("src", "../image/touxiang.jpg");
        } else {
            $(".headerPic").find("img").eq(0).attr("src", head_pic);
        }

        getOrdernumber(identitySwitch);
        getUserMoney();
        //接收监听
        api.addEventListener({
            name: 'reGetMyInfo'
        }, function (ret) {
            if (ret && ret.value) {
                getStorageAll();
                $('.divCell').text(company);
                getOrdernumber(identitySwitch);
                getUserMoney();
            }
        });
        //接收修改名字的监听
        api.addEventListener({
            name: 'modifyName'
        }, function (ret, err) {
            if (ret && ret.value) {
                $('.companyName').text(nick_name);

            }
        });
        //接收修改个人资料的监听
        api.addEventListener({
            name: 'modifyInfo'
        }, function (ret, err) {
            if (ret && ret.value) {
                getStorageAll();
                $(".companyName").text(nick_name)
                $(".headerPic").find("img").eq(0).attr("src", head_pic);

            }
        });
        //接收监听，用户删除订单等操作更新订单数量
        api.addEventListener({
            name: 'updateCart'
        }, function (ret) {
            if (ret && ret.value) {
                getOrdernumber(identitySwitch);
            }
        });
//接收提交资料审核，更新个人信息
        api.addEventListener({
            name: 'sendAuthentication'
        }, function (ret, err) {
            if (ret && ret.value) {
                checkNewInfo();

            }
        });

        //接收监听，用户删除订单等操作更新订单数量
        api.addEventListener({
            name: 'updateOrderNum'
        }, function (ret) {
            if (ret && ret.value) {
                getOrdernumber(identitySwitch);
            }
        });
        //接收修改名字的监听
        api.addEventListener({
            name: 'modifyName'
        }, function (ret) {
            if (ret && ret.value) {
                $(".companyName").text(ret.value.newName)
            }
        });

        //清除消息数的监听
        api.addEventListener({
            name: 'clearMessageCount'
        }, function (ret) {
            $('.noMessage').removeClass('myMessage');
            myInfoData.sms_user_count=0;
            myInfoData.sms_express_count=0;
            api.execScript({
                name: 'root',
                script: 'clearMessageCount()'
            })
        });

        api.addEventListener({
            name: 'clearMessageCountFriend'
        }, function (ret) {
            myInfoData.sms_user_count=0;
        });

        api.execScript({
            name: 'root',
            script: 'hasNewMessage()'
        });

        if (api.systemType == 'ios') {
            $('.headerPic').css({'margin-top': '10px'})
        }
    }

    function checkNewInfo(isForceNew) {
        if (isForceNew) {
            $('.noMessage').addClass('myMessage');
        }
        getStorageAll();
        var url = '/User/userInfo/?userName=' + user_name;
        ajaxRequest(url, 'get', {}, function (ret, err) {
            if (ret.status == 1) {
//                 alert(JSON.stringify(ret.msg))

                myInfoData = ret.msg;
                if (!$('.noMessage').hasClass('myMessage') && (ret.msg.sms_user_count || ret.msg.sms_express_count)) {
                    $('.noMessage').addClass('myMessage');
                }

                if (ret.msg.nickname) {
                    $('#individualFrame .companyName').text(ret.msg.nickname);
                }
                if (ret.msg.head_portrait) {
                    $("#individualFrame .headerPic").find("img").eq(0).attr("src", ret.msg.head_portrait);
                }

                if(ret.msg.company.company){
                    $('#companyFrame .companyName').text(ret.msg.company.company);
                }
                if (ret.msg.company.thumb) {
                    $("#companyFrame .headerPic").find("img").eq(0).attr("src", ret.msg.company.thumb);
                }
            }
        })
    }

    function go2News() {
        api.openWin({
            name: 'my/news',
            url: 'my/news.html',
            pageParam: {
                myInfoData: myInfoData
            }
        });
    }

    //获取订单分类数量
    function getOrdernumber(identitySwitch) {
        // showLoading();
        data = {
            identitySwitch: identitySwitch,
            userName: user_name,
        };
        url = "User/index";
        ajaxRequest(url, 'post', data, function (ret, err) {
            if (ret.status == 1) {
//                alert(JSON.stringify(ret.msg.pendingPayment));
                $('#pendingPayment').text(ret.msg.pendingPayment);
                $('#alreadyPaid').text(ret.msg.alreadyPaid);
                $('#alreadyShipped').text(ret.msg.alreadyShipped);
                $('#SuccessfulTrade').text(ret.msg.SuccessfulTrade);
                $('#returns').html(ret.msg.returns);
            } else {
                api.toast({
                    msg: '数据错误',
                    duration: 2000,
                    location: 'bottom'
                });
            }
        });
        // hideLoading();
    }


    $(function () {
        $('#switch2Seller').unbind('click').bind('click', function () {
            changeStatus('seller');
        });

        $('#switch2Buyer').unbind('click').bind('click', function () {
            changeStatus('buyer');
        });
    })

    //切换为卖家
    function changeStatus(status) {

        if (myInfoData.company) {
            if (myInfoData.company.validated) {
                identitySwitch = status;//切换用户类型
                if (status == "seller") {
                    $(".buyer").css({"display": "none"});
                    $(".seller").css({"display": "block"});
                    $("header").addClass("headerBuyer");


                    $('#individualFrame').hide();
                    $('#companyFrame').show();
                } else {

                    $(".buyer").css({"display": "block"});
                    $(".seller").css({"display": "none"});
                    $("header").removeClass("headerBuyer");


                    $('#individualFrame').show();
                    $('#companyFrame').hide();
                }
                getOrdernumber(status);
            } else {
                openToTwo("my/comAuthenticationWait_win");
            }

        } else {
            if (confirm("切换为卖家模式需要先认证")) {
                api.openWin({
                    name: ' comAuthentiction',
                    url: 'my/comAuthentiction_win.html'
                });
            }
        }

    }

    //获取钱包余额
    function getUserMoney() {
        // showLoading();
        var data = {
            userName: user_name,
        };
        var url = 'User/userInfo';
        ajaxRequest(url, 'post', data, function (ret, err) {
            if (ret.status == 1) {
                $('#userMoney').text(ret.msg.money);
            } else {
                api.toast({
                    msg: ret.msg,
                    duration: 2000,
                    location: 'bottom'
                });
            }
        });
        // hideLoading();
    }

    function goToOrderList(status) {
        var goUrl;
        if (identitySwitch == "buyer") {
            goUrl = "my/buyerOrderList_win.html"
        } else {
            goUrl = "my/sellerOrderList_win.html"
        }
        api.openWin({
            name: "goToOrderList",
            url: goUrl,
            pageParam: {
                status: status
            }
        })
    }
    function modifyInfo() {
//        api.openFrame({
//            name: 'modifyInfo_frm',
//            url: 'my/modifyInfo_frm.html',
//            rect: {
//                x: 0,
//                y: 0,
//                w: 'auto',
//                h: 'auto'
//            },
//            bounces: false,
//            vScrollBarEnabled: false,
//            hScrollBarEnabled: false,
//            animation: {
//                type: "push",                //动画类型（详见动画类型常量）
//                subType: "from_right",       //动画子类型（详见动画子类型常量）
//                duration: 300
//            },
//            pageParam: {
////                name:$(".companyName").text(),
////                user_name:user_name,
////                head_pic:head_pic
//            }
//        });
    }

</script>
</html>